package com.qhhc.service.impl;

import com.qhhc.entity.CarComment;
import com.qhhc.mapper.CarCommentMapper;
import com.qhhc.service.CarCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class CarCommentServiceImpl implements CarCommentService {

    @Autowired
    private CarCommentMapper carCommentMapper;

    @Override
    public List<CarComment> getCommentsByCarId(Long carId) {
        return carCommentMapper.selectByCarId(carId);
    }

    @Override
    public List<CarComment> getCommentsByUserId(Long userId) {
        return carCommentMapper.selectByUserId(userId);
    }

    @Override
    public CarComment getCommentById(Long commentId) {
        return carCommentMapper.selectById(commentId);
    }

    @Override
    public List<CarComment> getAllComments() {
        return carCommentMapper.selectAll();
    }

    @Override
    @Transactional
    public boolean addComment(CarComment comment) {
        return carCommentMapper.insert(comment) > 0;
    }

    @Override
    @Transactional
    public boolean updateComment(CarComment comment) {
        return carCommentMapper.update(comment) > 0;
    }

    @Override
    @Transactional
    public boolean deleteComment(Long commentId) {
        return carCommentMapper.deleteById(commentId) > 0;
    }

    @Override
    @Transactional
    public boolean deleteCommentsByCarId(Long carId) {
        return carCommentMapper.deleteByCarId(carId) > 0;
    }

    @Override
    @Transactional
    public boolean deleteCommentsByUserId(Long userId) {
        return carCommentMapper.deleteByUserId(userId) > 0;
    }

    @Override
    public List<CarComment> getCommentsByCondition(CarComment comment) {
        return carCommentMapper.selectByCondition(comment);
    }
} 